package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.JiajiaMallShopProductInformation;
import com.ruoyi.system.domain.vo.JiajiaMallShopProductInformationVo;
import com.ruoyi.system.mapper.JiajiaMallShopProductInformationMapper;
import com.ruoyi.system.service.IJiajiaMallShopProductInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 商城产品信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Service
public class JiajiaMallShopProductInformationServiceImpl implements IJiajiaMallShopProductInformationService 
{
    @Autowired
    private JiajiaMallShopProductInformationMapper jiajiaMallShopProductInformationMapper;

    /**
     * 查询商城产品信息
     * 
     * @param id 商城产品信息主键
     * @return 商城产品信息
     */
    @Override
    public JiajiaMallShopProductInformationVo selectJiajiaMallShopProductInformationById(Long id)
    {
        return jiajiaMallShopProductInformationMapper.selectJiajiaMallShopProductInformationById(id);
    }

    /**
     * 查询商城产品信息列表
     * 
     * @param jiajiaMallShopProductInformation 商城产品信息
     * @return 商城产品信息
     */
    @Override
    public List<JiajiaMallShopProductInformationVo> selectJiajiaMallShopProductInformationList(JiajiaMallShopProductInformation jiajiaMallShopProductInformation)
    {
        List<JiajiaMallShopProductInformationVo> jiajiaMallShopProductInformationVos = jiajiaMallShopProductInformationMapper.selectJiajiaMallShopProductInformationList(jiajiaMallShopProductInformation);
        jiajiaMallShopProductInformationVos.stream().forEach(a ->{
            a.setPhotoUrlIdsList(Arrays.asList(a.getPhotoUrlIds().split(";")));
        });
        return jiajiaMallShopProductInformationVos;
    }

    /**
     * 新增商城产品信息
     * 
     * @param jiajiaMallShopProductInformation 商城产品信息
     * @return 结果
     */
    @Override
    public int insertJiajiaMallShopProductInformation(JiajiaMallShopProductInformation jiajiaMallShopProductInformation)
    {
        jiajiaMallShopProductInformation.setCreateTime(DateUtils.getNowDate());
        jiajiaMallShopProductInformation.setRemoveShelf(1);
        return jiajiaMallShopProductInformationMapper.insertJiajiaMallShopProductInformation(jiajiaMallShopProductInformation);
    }

    /**
     * 修改商城产品信息
     * 
     * @param jiajiaMallShopProductInformation 商城产品信息
     * @return 结果
     */
    @Override
    public int updateJiajiaMallShopProductInformation(JiajiaMallShopProductInformation jiajiaMallShopProductInformation)
    {
        jiajiaMallShopProductInformation.setUpdateTime(DateUtils.getNowDate());
        return jiajiaMallShopProductInformationMapper.updateJiajiaMallShopProductInformation(jiajiaMallShopProductInformation);
    }

    /**
     * 批量删除商城产品信息
     * 
     * @param ids 需要删除的商城产品信息主键
     * @return 结果
     */
    @Override
    public int deleteJiajiaMallShopProductInformationByIds(String ids)
    {
        return jiajiaMallShopProductInformationMapper.deleteJiajiaMallShopProductInformationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除商城产品信息信息
     * 
     * @param id 商城产品信息主键
     * @return 结果
     */
    @Override
    public int deleteJiajiaMallShopProductInformationById(Long id)
    {
        return jiajiaMallShopProductInformationMapper.deleteJiajiaMallShopProductInformationById(id);
    }
}
